package durst.action.account;

import java.sql.SQLException;
import java.util.List;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.validation.Validate;
import net.sourceforge.stripes.validation.ValidateNestedProperties;
import durst.action.CalendarBasicAction;
import durst.data.Event;
import durst.data.Invite;
import durst.data.UserCalendar;
import durst.data.dao.DaoFactory;
import durst.data.dao.impl.InviteDao;
import durst.data.dao.impl.UserCalendarDao;

public class JumplistAction extends CalendarBasicAction {
	@ValidateNestedProperties(@Validate(field = "id"))
	private List<Event> events;

	@ValidateNestedProperties(@Validate(field = "id"))
	private List<UserCalendar> cals;

	@Validate(required = true)
	private boolean jumplist;

	@SuppressWarnings("unchecked")
	@DefaultHandler
	public Resolution handle() throws SQLException {
		if (events != null && events.size() > 0)
			((InviteDao<Invite, Integer>) DaoFactory.getInstance().createDao(Invite.class))
					.jumplist(context.getAccount(), events, jumplist);
		if (cals != null && cals.size() > 0)
			((UserCalendarDao<UserCalendar, Integer>) DaoFactory.getInstance().createDao(
					UserCalendar.class)).jumplist(context.getAccount(), cals, jumplist);

		return new RedirectResolution(ManageAccountActionBean.class);
	}

	public List<Event> getEvents() {
		return events;
	}

	public void setEvents(List<Event> events) {
		this.events = events;
	}

	public List<UserCalendar> getCals() {
		return cals;
	}

	public void setCals(List<UserCalendar> cals) {
		this.cals = cals;
	}

	public boolean isJumplist() {
		return jumplist;
	}

	public void setJumplist(boolean jumplist) {
		this.jumplist = jumplist;
	}

}
